home *** CD-ROM | disk | FTP | other *** search
- ''
- '' $Id: RPDump.bas,v 1.3 1994/04/29 15:46:21 alex Rel $
- ''
- '' How to dump a RastPort to the printer
- ''
- '' Derived from RKM example (c) Copyright 1992 Commodore-Amiga, Inc.
- ''
-
- DEFINT A-Z
-
- 'REM $INCLUDE Exec.bh
- 'REM $INCLUDE Graphics.bh
- 'REM $INCLUDE Intuition.bh
- 'REM $INCLUDE DOS.bc
- 'REM $INCLUDE Printer.bc
-
- REM $INCLUDE BLib/ExecSupport.bas
-
- LIBRARY OPEN "exec.library", LIBRARY_MINIMUM&
- LIBRARY OPEN "graphics.library", LIBRARY_MINIMUM&
- LIBRARY OPEN "intuition.library", LIBRARY_MINIMUM&
-
- FUNCTION dumpRP(BYVAL rp&, BYVAL cm&, BYVAL modeID&, ibox(4), BYVAL userAbort&)
- STATIC pmp&, pio&, pd&, pio&, sigfr&, junk&, r
-
- dumpRP = -1 'generic failure
-
- ' Create private messageport
- pmp& = CreatePort&(NULL&, 0)
- IF pmp& <> NULL& THEN
- ' Allocate Printer IO block
- pio& = CreateExtIO&(pmp&, IODRPReq_sizeof)
- IF pio& <> NULL& THEN
- ' Open the printer.device
- r = OpenDevice&(SADD("printer.device" + CHR$(0)), 0, pio&, 0)
- IF r = 0 THEN
- ' Fill in the IODRPRequest
- POKEW pio& + IODRPReqio_Command, PRD_DUMPRPORT&
- POKEL pio& + io_RastPort, rp&
- POKEL pio& + io_ColorMap, cm&
- POKEL pio& + io_Modes, modeID&
- POKEW pio& + io_SrcX, ibox(0)
- POKEW pio& + io_SrcY, ibox(1)
- POKEW pio& + io_SrcWidth, ibox(2)
- POKEW pio& + io_SrcHeight, ibox(3)
-
- POKEL pio& + io_DestCols, 0
- POKEL pio& + io_DestRows, 0
- POKEW pio& + io_Special, SPECIAL_ASPECT&
-
- ' Always give the user a change to abort.
- ' So we'll use SendIO(), instead of DoIO(), to be asynch and
- ' catch a possible user request to abort printing
-
- SendIO pio&
-
- ' Now Wait() for either a user signal or a printer.device signal
-
- sigfr& = xWait&((1& << PEEKB(pmp& + mp_SigBit)) OR userAbort&)
-
- IF sigfr& AND userAbort& THEN
- ' User wants to abort
-
- AbortIO pio&
- junk& = WaitIO&(pio&)
- END IF
-
- IF sigfr& AND (1& << PEEKB(pmp& + mp_SigBit)) THEN
- ' printer is either ready or an error has occurred
-
- WHILE GetMsg&(pmp&)
- ' Remove any messages
- WEND
- END IF
-
- ' Return error code (in this case we count user-abort as an error)
- dumpRP = PEEKB(pio& + IODRPReqio_Error)
-
- CloseDevice pio&
- ELSE
- dumpRP = r
- END IF
- DeleteExtIO pio&
- END IF
- DeletePort pmp&
- END IF
- END FUNCTION
-
- '
- ' How to use dumpRP to dump the contents of a window
- '
- FUNCTION dumpWindow(BYVAL win&, BYVAL userAbort&)
- STATIC scr&, vp&, rp&, cm&, modeID&, junk
- DIM ibox(4)
-
- scr& = PEEKL(win& + WScreen) ' the window's screen
- vp& = scr& + ScreenViewPort ' the ViewPort associated with the screen
- IF PEEKW(LIBRARY("graphics.library") + lib_Version) >= 36 THEN
- modeID& = GetVPModeID&(vp&)
- ELSE
- modeID& = PEEKW(vp& + ViewPortModes) AND &hffff&
- END IF
- cm& = PEEKL(vp& + ColorMap) ' the ViewPort's colour map
- rp& = PEEKL(win& + RPort) ' the window's rastport
- ibox(0) = PEEKW(win& + WindowLeftEdge)
- ibox(1) = PEEKW(win& + WindowTopEdge)
- ibox(2) = PEEKW(win& + WindowWidth)
- ibox(3) = PEEKW(win& + WindowHeight)
-
- dumpWindow = dumpRP(rp&, cm&, modeID&, ibox(), userAbort&)
- END FUNCTION
-
- '
- ' How to use dumpRP to dump a screen
- '
- FUNCTION dumpScreen(BYVAL scr&, BYVAL userAbort&)
- STATIC scr&, vp&, rp&, cm&, modeID&
- DIM ibox(4)
-
- vp& = scr& + ScreenViewPort ' the ViewPort associated with the screen
- IF PEEKW(LIBRARY("graphics.library") + lib_Version) >= 36 THEN
- modeID& = GetVPModeID&(vp&)
- ELSE
- modeID& = PEEKW(vp& + ViewPortModes) AND &hffff&
- END IF
- cm& = PEEKL(vp& + ColorMap) ' the ViewPort's colour map
- rp& = scr& + RastPort ' the screen's rastport
- ibox(0) = PEEKW(scr& + ScreenLeftEdge)
- ibox(1) = PEEKW(scr& + ScreenTopEdge)
- ibox(2) = PEEKW(scr& + ScreenWidth)
- ibox(3) = PEEKW(scr& + ScreenHeight)
-
- dumpScreen = dumpRP(rp&, cm&, modeID&, ibox(), 0)
- END FUNCTION
-
- '
- ' This one's just for illustration, how to use our dumpRP routine to dump
- ' the current front-most screen (which is not necessarily one of BASIC's)
- '
- FUNCTION dumpFrontScreen(BYVAL userAbort&)
- STATIC ilock&, scr&
-
- ilock& = LockIBase&(0) ' lock IntuitionBase
- ' if you call anything high level here, the system will dead-lock
-
- scr& = PEEKL(LIBRARY("intuition.library") + FirstScreen)
- ' we should attempt to lock the screen open here, but since the front
- ' screen may be private, we can't LockPubScreen it, lets just play
- ' fast'n'loose & hope that the screen doesn't go away...
-
- UnlockIBase ilock& ' release IntuitionBase lock
-
- dumpFrontScreen = dumpScreen(scr&, userAbort&)
- END FUNCTION
-
- '
- ' A quick re-implementation of BASIC's PCOPY command, print the screen which
- ' has BASIC's idea of the current window on it (no way to quit, no errors, not
- ' a good routine in many ways...)
- '
- SUB ourPCOPY
- STATIC junk
-
- junk = dumpScreen(WINDOW(7) + WScreen, 0)
- END SUB
-
- '
- ' Turn an error code (IOERR from Exec or PDERR from the printer) into a string
- ' explaining what went wrong
- '
- FUNCTION drpErrorString$(BYVAL r)
- SELECT CASE r&
- CASE IOERR_OPENFAIL
- drpErrorString$ = "device/unit failed to open"
-
- CASE IOERR_ABORTED
- drpErrorString$ = "request terminated early"
-
- CASE IOERR_NOCMD
- drpErrorString$ = "command not supported by device"
-
- CASE IOERR_BADLENGTH
- drpErrorString$ = "not a valid length"
-
- CASE IOERR_BADADDRESS
- drpErrorString$ = "invalid address (misaligned or bad range)"
-
- CASE IOERR_UNITBUSY
- drpErrorString$ = "device opens ok, but requested unit is busy"
-
- CASE IOERR_SELFTEST
- drpErrorString$ = "hardware failed self-test"
-
- CASE PDERR_CANCEL
- drpErrorString$ = "user cancelled print"
-
- CASE PDERR_NOTGRAPHICS
- drpErrorString$ = "printer cannot output graphics"
-
- CASE PDERR_BADDIMENSION
- drpErrorString$ = "print dimensions illegal"
-
- CASE PDERR_INTERNALMEMORY
- drpErrorString$ = "no memory for internal variables"
-
- CASE PDERR_BUFFERMEMORY
- drpErrorString$ = "no memory for print buffer"
-
- CASE ELSE
- drpErrorString$ = ""
- END SELECT
- END FUNCTION
-
- SUB main
- STATIC r
-
- ' We'll print the contents, of BASIC's default window; this code works
- ' out the necessary values
- ' Since BASIC normally uses a gimme-zero-zero window, the associated window
- ' RastPort has none of the window furniture in it
-
- ' Draw something in the window (imaginative huh...)
- COLOR 3
- LOCATE 9, 13
- PRINT "Hello World"
- COLOR 1
-
- ' we pass ^C as a possible user abort signal; Program[Break] from the
- ' HiSoft BASIC Editor would cause such a signal to be generated, or you
- ' could use the Break command from a CLI
-
- r = dumpWindow(WINDOW(7), SIGBREAKF_CTRL_C&)
-
- IF r <> 0 THEN
- PRINT drpErrorString$(r)
- END IF
-
- ' Now dump the front-most screen (could be any screen in the system)
-
- r = dumpFrontScreen(SIGBREAKF_CTRL_C&)
- IF r <> 0 THEN
- PRINT drpErrorString$(r)
- END IF
- END SUB
-
- main
- END
-